<include file="Public/header"/>
<div class="x-nav">
      <span class="layui-breadcrumb">

      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <style>
        .layui-upload-img-dd {
            width: 92px;
            height: 92px;
            margin: 0 10px 10px 0;
            float: left;
            position: relative;
        }

        .layui-upload-img-dd img {
            width: 100%;
            height: 100%;
        }
        .layui-upload-img-dd a {
            position: absolute;
            right: 0;
            top: 0;
            background-color: #009688;
            height: 20px;
            line-height: 20px;
            color: #ffffff;
            font-size: 5px;
            padding: 0 2px;
        }

        .input-group{
            position: relative;
            text-align: center;
            height: 38px;

        }
        .clearfix{*zoom:1;}
        .input-group .layui-input-inline{
            margin-right: 0px;
        }
        .input-group .input-group-addon,.input-group-btn,.add-attr-input{
            float: left;
            height: 38px;
            line-height: 38px;
            border: 1px solid #e6e6e6;
            box-sizing: border-box;
            padding-left: 10px;
            padding-right: 10px;
        }
        .input-group .input-group-addon{
            border-right: none;
            background-color: #eeeeee;
            color: #98999a;
        }
        .input-group .input-group-btn{
            border-left: none;
        }
        .attr-group {
            border: 1px solid #eee;
            padding: .5rem .75rem;
            margin-bottom: .5rem;
            border-radius: .15rem;
        }

        .attr-group-delete {
            display: inline-block;
            background: #eee;
            color: #fff;
            width: 1rem;
            height: 1rem;
            text-align: center;
            line-height: 1rem;
            border-radius: 999px;
        }

        .attr-group-delete:hover {
            background: #ff4544;
            color: #fff;
            text-decoration: none;
        }

        .attr-list > div {
            vertical-align: top;
        }

        .attr-item {
            display: inline-block;
            background: #eee;
            margin-right: 1rem;
            margin-top: .5rem;
            overflow: hidden;
        }

        .attr-item .attr-name {
            padding: .15rem .75rem;
            display: inline-block;
        }

        .attr-item .attr-delete {
            padding: .35rem .75rem;
            background: #d4cece;
            color: #fff;
            font-size: 1rem;
            font-weight: bold;
        }

        .attr-item .attr-delete:hover {
            text-decoration: none;
            color: #fff;
            background: #ff4544;
        }
        .input-group .add-attr-input{

        }
        .table-bordered{
            width: 100%;
        }
        .table-bordered td,th{
            border: solid 1px #eeeeee;
            padding: 10px 20px;

        }

    </style>

    <form class="layui-form" action="{:U('update')}" method="post">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>团购期数
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <input type="text" id="periods" name="periods" required="" lay-verify="required"
                       autocomplete="off" value="{$data['periods']|default=date('Ymd')}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>    
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>活动标题
            </label>

            <div class="layui-input-inline" style="width:80%;">
                <input type="text" id="name" name="name" required="" lay-verify="required" autocomplete="off" value="{$data['name']}" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>    
          

        <div class="layui-form-item">
            <label for="produce" class="layui-form-label">
                <span class="x-red">*</span>活动描述
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <input type="text"  placeholder="请简要描述一下活动" value="{$data['desc']}" id="desc" name="desc"
                     required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                <span class="x-red">*</span>活动时间
            </label>
            <div class="layui-input-inline">
                <input class="layui-input" placeholder="开始时间"  required="" lay-verify="required"
                value="<if condition='$data.id neq 0'>{$data['start_time']|date='Y-m-d H:i:s',###}</if>" name="start_time" id="start">

            </div>
            <div class="layui-input-inline">
                <input class="layui-input" placeholder="截止时间"  required="" lay-verify="required"
                value="<if condition='$data.id neq 0'>{$data['end_time']|date='Y-m-d H:i:s',###}</if>" name="end_time" id="end">

            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>


        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                <span class="x-red">*</span>提货时间
            </label>
            <div class="layui-input-inline">
                <input class="layui-input" placeholder="开始时间"  required="" lay-verify="required"
                value="<if condition='$data.id neq 0'>{$data['tihuo_start_time']|date='Y-m-d H:i:s',###}</if>" name="tihuo_start_time" id="tihuo_start">
            </div>
            <div class="layui-input-inline">
                <input class="layui-input" placeholder="截止时间"  required="" lay-verify="required"
                value="<if condition='$data.id neq 0'>{$data['tihuo_end_time']|date='Y-m-d H:i:s',###}</if>" name="tihuo_end_time" id="tihuo_end">
            </div> 
           <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>           
        </div> 
        <!--
        <div class="layui-form-item">
            <label for="nickname" class="layui-form-label">
                <span class="x-red">*</span>发起者昵称
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <input type="text" value="{$data['nickname']}" id="nickname" name="nickname" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
                
        <div class="layui-form-item">
            <label for="header" class="layui-form-label">
                <span class="x-red"></span>发起者头像
            </label>
            <div class="layui-input-inline">
                <div class="layui-upload-list">
                    <input type="hidden" name="header"  value="{$data['header']}" >
                    <img class="layui-upload-img" style="width: 100px;" id="avatar-preview" src="{$data['header']}">
                    <p id="demoText"></p>
                </div>
                <button type="button" class="layui-btn" id="avatar-btn">
                    <i class="layui-icon">&#xe67c;</i>上传头像
                </button>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div> 
        <div class="layui-form-item">
            <label for="mobile" class="layui-form-label">
                <span class="x-red">*</span>活动电话
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <input type="number" value="{$data['mobile']}" id="mobile" name="mobile" required="" lay-verify="number"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
		-->
        <div class="layui-form-item">
            <label for="sort" class="layui-form-label">
                <span class="x-red">*</span>自定义排序
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <input type="number" value="{$data['sort']|default=0}" id="sort" name="sort" required="" lay-verify="number"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
 		<!--  
         <div class="layui-form-item">
            <label for="is_coupon" class="layui-form-label">
                <span class="x-red">*</span>是否可用优惠卷
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <select name="is_coupon">
                    <option value="1" <php>if($data['is_coupon'] == 1) echo 'selected'</php>>可用</option>
                    <option value="2" <php>if($data['is_coupon'] == 2) echo 'selected'</php>>不可用</option>
                </select>
            </div>
        </div> 
 
         <div class="layui-form-item">
            <label for="coupon_code" class="layui-form-label">
                <span class="x-red">*</span>优惠卷编码
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <input type="text" value="{$data['coupon_code']}" id="coupon_code" name="coupon_code" 
                    placeholder="多个用，分隔"   autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>多个用，分隔
            </div>
        </div>
        
        -->
                            
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>活动状态
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <select name="status">
                    <option value="1" <php>if($data['status'] == 1) echo 'selected'</php>>上架</option>
                    <option value="2" <php>if($data['status'] == 2) echo 'selected'</php>>下架</option>
                </select>
            </div>
        </div>       
 		<!--  
        <div class="layui-form-item">
            <label for="is_home" class="layui-form-label">
                <span class="x-red">*</span>是否首页显示
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <select name="is_home">
                    <option value="1" <php>if($data['is_home'] == 1 ) echo 'selected'</php>>是</option>
                    <option value="2" <php>if($data['is_home'] == 2) echo 'selected'</php>>否</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="is_jielong" class="layui-form-label">
                <span class="x-red">*</span>是否显示接龙列表
            </label>
            <div class="layui-input-inline" style="width:80%;">
                <select name="is_jielong">
                    <option value="1" <php>if($data['is_jielong'] == 1) echo 'selected'</php>>显示</option>
                    <option value="2" <php>if($data['is_jielong'] == 2) echo 'selected'</php>>不显示</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item" >
            <label class="layui-form-label">媒体信息</label>
            <div class="layui-input-block" style="width:80%;">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="test2">图组上传</button>
                    <div hidden id="summary-img-input">
                        <volist name="imgs" id="vo">
                            <input type="hidden" name="summary_imgs[]" value="{$vo}">
                        </volist>
                    </div>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;overflow: hidden">
                        预览图：
                        <div class="layui-upload-list clearfix" id="demo2">
                            <volist name="imgs" id="val">
                            <dd class="layui-upload-img-dd"><img src="{$val}"  ><a href="javascript:void(0);" class="layui-upload-img-span">删除</a></dd>
                            </volist>
                        </div>
                    </blockquote>
                </div>

            </div>
        </div>
		-->
        <div class="layui-form-item">
        	<input type="hidden" name="id" value="{$data['id']}">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="submit" lay-submit="submit">
                保存
            </button>
        </div>
    </form>
</div>

<script>


    layui.use(['form','layer','upload','laydate'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
        var upload = layui.upload;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#start', //指定元素
            type:'datetime'
        });
        laydate.render({
            elem: '#end' //指定元素
            ,type:'datetime'
        });
        laydate.render({
            elem: '#tihuo_start', //指定元素
            type:'datetime'
        });
        laydate.render({
            elem: '#tihuo_end' //指定元素
            ,type:'datetime'
        });
        var uploadInst = upload.render({
            elem: '#avatar-btn'
            ,url: "{:U('Upload/uploadpic')}"
            ,data:{
                name:'img'

            }
            ,field:'img'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#avatar-preview').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){


                if(res.code!=0){
                    layer.msg(res.msg,{icon: 5});

                }
                //上传成功
                if(res.code==0 ){
                    layer.msg('上传成功',{icon: 6});
                    $("[name='header']").val(res.data);

                }

            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


        upload.render({
            elem: '#test2'
            ,url: "{:U('upload/uploadpic')}"
            ,multiple: true
            ,data:{
                name:'img'
            }
            ,field:'img'
            ,before: function(obj){

                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    var demo = $('#demo2');
                    demo.append('<dd class="layui-upload-img-dd"><img src="'+ result +'" alt="'+ file.name +'" ><a href="javascript:void(0);" class="layui-upload-img-span">删除</a></dd>');



                });

            }
            ,done: function(res){
                //上传完毕
                var summary_img_input_content = $('#summary-img-input');
                summary_img_input_content.append('<input type="hidden" name="summary_imgs[]" value="'+res.data+'">');

            }
        });

        $('#demo2').on('click','.layui-upload-img-span',function () {
            var input_index = $(this).parent('dd').index();
            $(this).parent('dd').remove();
            $('#summary-img-input ').find("input[name='summary_imgs[]']").eq(input_index).remove();
        });
    });
</script>
<include file="Public/footer"/>